package config.xml;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.JOptionPane;

public class DBuse {
	public static ArrayList<String> getTableNames() throws SQLException {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		ArrayList<String> tableNames = new ArrayList<String>();
		try {
			Connection conn = DriverManager.getConnection(
					"jdbc:mysql://localhost:3306/" + file.getDBname(),
					file.getUser(), file.getPassword());
			DatabaseMetaData dbMetaData;
			dbMetaData = conn.getMetaData();
			String[] types = { "TABLE" };
			ResultSet rs = dbMetaData.getTables(null, null, "%", types);
			while (rs.next()) {
				String tableName = rs.getString("TABLE_NAME");
				tableNames.add(tableName);
			}
			JOptionPane.showMessageDialog(null, "mybatis-generator配置文件生成成功！");
		} catch (SQLException e) {
			JOptionPane.showMessageDialog(null, "输入错误 请重新输入！");
			// e.printStackTrace();
		}
		return tableNames;

	}

}
